
#ifndef _TTG_UTILS_UTILMANAGERDLL_
#define _TTG_UTILS_UTILMANAGERDLL_
#include "Common/Definitions.h"

#include <vector>
#include <string>
#include "Common/Math.h"

namespace ttg_internal
{
	namespace utils
	{
		//Static wrapper for dll functions.
		//Provices references to functions and binding routines.
		//Note: it will be binded by UtilManager service (at start).
		class UtilManagerDll
		{
			private:
				static UtilManagerDll *ref;
				//Returns potential pathes to UtilManager.dll.
				static std::vector<std::string> getDllFiles();
				//Create wrapper with nulled references.
				UtilManagerDll();
			public:
				//Tries to bind dll.
				//In case of error returns false (without throwing ttg::Error).
				bool bind();
				//Tries to unbind dll.
				//In case of error returns false (without throwing ttg::Error).
				bool unBind();
				//Returns reference to instance.
				static inline UtilManagerDll *getRef()
				{
					if (ref == NULL)
						ref = new UtilManagerDll();
					return ref;
				}
			public:
				//----------------------
				//--- Initialization ---
				//----------------------
				//Inits UtilManager.
				void (__stdcall *init)();
				//Shows tray icon. User will be able to load additional utilities.
				void (__stdcall *activateWindow)();
				//Closes UtilManager.
				void (__stdcall *close)();
				//------------------
				//--- Parameters ---
				//------------------
				//Creates set of parameters.
				ttg::math::uint64 (__stdcall *createParameterSet)(const char *name, ttg::math::uint64 root);
				//Creates set of parameters in the root set.
				ttg::math::uint64 (__stdcall *createRootParameterSet)(const char *name);
				//Releases set of parameters.
				void (__stdcall *releaseParameterSet)(ttg::math::uint64 ID);
				//Creates parameter.
				ttg::math::uint64 (__stdcall *createParameter)(const char *name,
															   const char *type,
															   ttg::math::uint64 root);
				//Creates parameter in the root set.
				ttg::math::uint64 (__stdcall *createRootParameter)(const char *name,
																   const char *type);
				//Releases required parameter.
				void (__stdcall *releaseParameter)(ttg::math::uint64 ID);
				//Returns value of requred parameter.
				char *(__stdcall *getParameterValue)(ttg::math::uint64 ID);
				//Releases string, that was returned by UtilManager.
				void (__stdcall *releaseString)(char *value);
				//Sets new value.
				void (__stdcall *setParameterValue)(ttg::math::uint64 ID, const char *value);
				//Sets or skips ReadOnly flag.
				void (__stdcall *setParameterReadOnly)(ttg::math::uint64 ID, bool value);
				//Locks required parameter.
				void (__stdcall *lockParameter)(ttg::math::uint64 ID);
				//UnLocks required parameter.
				void (__stdcall *unLockParameter)(ttg::math::uint64 ID);
				//Returns true, if parameter was modified since last get().
				bool (__stdcall *wasParameterModified)(ttg::math::uint64 ID);
				//----------------
				//--- Pipeline ---
				//----------------
				//Creates pipeline avatar.
				ttg::math::uint64 (__stdcall *createPipeline)(void *serialized_pipeline,
								   ttg::math::uint64 size_in_bytes);
				//Releases pipeline avatar.
				void (__stdcall *releasePipeline)(ttg::math::uint64 ID);
				//-----------------
				//--- Utilities ---
				//-----------------
				//Inits required utility.
				void (__stdcall *initUtility)(void *serialized_props,
											  size_t size_in_bytes);
				//Updates state of the devices.
				void (__stdcall *updateUtility_Devices)(void *serialized_devices,
														size_t size_in_bytes);
				//Closes required utilities.
				void (__stdcall *closeUtility)(const char *name);
		};
	}
}

#endif
